package com.example.morealipy.util;

import com.example.morealipy.activity.MainActivity;
import com.example.morealipy.activity.MoreActivity;
import com.example.morealipy.app.App;
import com.example.morealipy.constant.Constant;
import com.example.morealipy.interfaces.LoadApplyInterface;
import com.example.morealipy.model.ApplySaveType;
import com.example.morealipy.model.ApplyTable;

import java.util.ArrayList;

public class LoadApplyImpl implements LoadApplyInterface {
    private MoreActivity moreActivity;
    public LoadApplyImpl(MoreActivity moreActivity){
        this.moreActivity = moreActivity;
    }
    @Override
    public void lodeApplyRequest() {

        //下面全部的试图（除去我的应用的全部视图）
        ArrayList<ApplyTable> appayTableMore = (ArrayList<ApplyTable>) ACache.get(App.getAppContext()).getAsObject(Constant.APPLY_MORE);
        //添加后的试图(我的应用)
        ArrayList<ApplyTable> appayTableUser = (ArrayList<ApplyTable>) ACache.get(App.getAppContext()).getAsObject(Constant.APPLY_USER);
        ArrayList<ApplySaveType> appayTableUserSave = (ArrayList<ApplySaveType>) ACache.get(App.getAppContext()).getAsObject(Constant.APPLY_ALL);
        if(appayTableMore==null){
            appayTableMore =ApplyTableManager.dynamicData();
            ACache.get(App.getAppContext()).put(Constant.APPLY_MORE,appayTableMore);
            ACache.get(App.getAppContext()).put(Constant.APPLY_USER,ApplyTableManager.mListUserData);
            ACache.get(App.getAppContext()).put(Constant.APPLY_ALL,ApplyTableManager.mListSave);
            appayTableUser = ApplyTableManager.mListUserData;
            appayTableUserSave = ApplyTableManager.mListSave;
        }
        moreActivity.returnMoreNewsApply(appayTableMore,appayTableUser,appayTableUserSave);
    }

    @Override
    public void onItemSwap(ArrayList<ApplyTable> applyTableList) {

    }

    @Override
    public void onItemAddOrRemove(ArrayList<ApplyTable> all, ArrayList<ApplyTable> head,ArrayList<ApplySaveType> mine) {
        ACache.get(App.getAppContext()).put(Constant.APPLY_MORE,all);
        ACache.get(App.getAppContext()).put(Constant.APPLY_USER,head);
        ACache.get(App.getAppContext()).put(Constant.APPLY_ALL,mine);
        MainActivity.getMa().applyRequest();
    }
}
